<template>
  <div class="popup flex-center flex-align-items-center">
    <div class="main">
      <div class="main-header">
        <p>{{ type === 1 ? '复制到' : '移动到' }}收藏夹</p>
        <i class="iconfont icon-guanbi" @click="close"></i>
      </div>
      <el-form ref="ruleFormRef" :model="form" :rules="rules" label-position="top" class="rule-form">
        <el-form-item prop="id">
          <el-select v-model="form.id" placeholder="请选择" style="width: 100%">
            <el-option v-for="item in list" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <div class="btns flex">
          <p class="font-14 pointer" @click="close">取消</p>
          <p class="font-14 pointer" @click="submitForm(ruleFormRef)">确定</p>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import { defineProps, defineEmits, ref, onMounted } from 'vue';
import api from '@/api/index';
import { ElMessage, ElLoading } from 'element-plus';

const props = defineProps(['selectList', 'type']);
const emit = defineEmits(['close', 'change']);

const rules = {
  id: [
    { required: true, message: '请选择收藏夹', trigger: 'blur' }
  ],
};

const list = ref([
  {
    id: 1,
    name: 'xxxx'
  }
]);
const form = ref({});
const ruleFormRef = ref();

const close = () => {
  emit('close', null);
}
const submitForm = async formEl => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
      // const loadingInstance = ElLoading.service({
      //   fullscreen: false,
      //   text: '提交中...'
      // });
      // loadingInstance.close();
      emit('change');
    } else {
      console.log('error submit!', fields)
    }
  })
}

onMounted(() => { });
</script>

<style lang="less" scoped>
.popup {
  .main {
    position: relative;
    width: 390px;
    border-radius: 10px;
    background: #fff;

    .rule-form {
      padding: 16px 24px;

      .btns {
        justify-content: end;
        margin-top: 25px;

        p {
          transition: .1s;
          padding: 10px 20px;
          border-radius: 4px;
          margin-left: 10px;

          &:last-child {
            color: #fff;
            background-color: #ff5277;
            border-color: #ff5277;

            &:hover {
              background: #ff7592;
              border-color: #ff7592;
              color: #fff;
            }
          }

          &:first-child {
            border: 1px solid #dcdfe6;
            color: #606266;

            &:hover {
              color: @main-color;
              border-color: #ffcbd6;
              background-color: #ffeef1;
            }
          }
        }
      }
    }
  }
}
</style>
